//
//  UIButton-Extension.swift
//  swiftWB
//
//  Created by mongyuan on 16/8/11.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

extension UIButton {
    
    // swift 中类方法是以class开头的方法
    /*
    class func createButton(imageName : String, bgImageName : String) -> UIButton {
        // 1.创建按钮
        let button = UIButton()
        
        // 2.设置button的属性
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        button.setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        button.setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        
        return button
    }
    */
    
    // convenience : 便利，使用convenience修饰的构造函数叫做便利构造函数
    // 便利构造函数通常用在对系统的类进行构造函数的扩充时使用
    /*
     1.便利构造函数通常都是写在extension里面
     2.便利构造函数init前面需要加convenience
     3.在便利构造函数中需要明确的调用self.init()
     */
    convenience init (imageName : String, bgImageName : String) {
        
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
    }
}




















